﻿using System;
using System.Collections.Generic;
using Assist;
using Autodesk.Revit.Creation;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace YJKRevitKernel.ElementAssistUtility
{
	public class ElementAssistMethod
	{
		public static bool GetFaces(object geoObject, ref FaceArray arFaces)
		{
			foreach (object obj in RevitVersionFuncs.GetGeometryObjectArray((geoObject as GeometryInstance).GetInstanceGeometry()))
			{
				if (obj is GeometryInstance)
				{
					return ElementAssistMethod.GetFaces(obj, ref arFaces);
				}
				if (obj is Solid)
				{
					foreach (object obj2 in (obj as Solid).Faces)
					{
						Face face = (Face)obj2;
						arFaces.Append(face);
					}
				}
			}
			return true;
		}

		public static FaceArray GetElementFaces(UIApplication uiApp, Autodesk.Revit.DB.Document doc, Element inputElement)
		{
			FaceArray faceArray = new FaceArray();
			Application create = uiApp.Application.Create;
			new ReferenceArray();
			Options options = create.NewGeometryOptions();
			options.ComputeReferences = true;
			options.View = doc.ActiveView;
			List<GeometryObject> geometryObjectArray = RevitVersionFuncs.GetGeometryObjectArray(inputElement.get_Geometry(options));
			for (int i = 0; i < geometryObjectArray.Count; i++)
			{
				GeometryObject geometryObject = geometryObjectArray[i];
				if (geometryObject is GeometryInstance)
				{
					ElementAssistMethod.GetFaces(geometryObject, ref faceArray);
				}
				else if (geometryObject is Solid)
				{
					foreach (object obj in (geometryObject as Solid).Faces)
					{
						Face face = (Face)obj;
						faceArray.Append(face);
					}
				}
			}
			return faceArray;
		}
	}
}
